package com.fkc.javahansoulbms.exception;

import com.fkc.javahansoulbms.util.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

// 全局异常处理
@ControllerAdvice
public class HandlerGlobalException {
	@ExceptionHandler(ComFoundException.class)
	@ResponseBody
	public Result handleComFoundException(ComFoundException e) {
		return Result.error().message(e.getMessage());
	}
	
	@ExceptionHandler(RuntimeException.class)
	@ResponseBody
	public Result handleRuntimeException(RuntimeException e) {
		return  Result.error().message("系统错误：" + e.getMessage());
	}
	
	@ExceptionHandler(Exception.class)
	@ResponseBody
	public Result handleException(Exception e){
		return Result.error().message("未知错误：" + e.getMessage());
	}
}
